﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:clr="clr-namespace:System;assembly=mscorlib" xmlns:clr2="clr-namespace:System.Collections;assembly=mscorlib" xmlns:local="clr-namespace:WPG" xmlns:data="clr-namespace:WPG.Data" xmlns:converters="clr-namespace:WPG.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
    
	<!-- PropertyGrid Style -->
	<Style TargetType="{x:Type local:PropertyGrid}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:PropertyGrid}">
                    <Border BorderThickness="1" BorderBrush="LightGray">
					<Grid>
						<Grid.RowDefinitions>
							<RowDefinition MinHeight="120" />
							<RowDefinition Height="Auto" />
						</Grid.RowDefinitions>

						<DockPanel Grid.Row="0" LastChildFill="True">

							<Grid DockPanel.Dock="Top" Background="LightGray">
								<Grid.ColumnDefinitions>
									<ColumnDefinition></ColumnDefinition>
									<ColumnDefinition Width="Auto"></ColumnDefinition>
								</Grid.ColumnDefinitions>

								<DockPanel Grid.Column="0">
									<DockPanel DockPanel.Dock="Top" Margin="6 2 0 4">
										<TextBlock DockPanel.Dock="Left" Name="PART_InstanceType" FontWeight="Bold" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}"></TextBlock>
										<TextBlock Width="6" DockPanel.Dock="Left" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}">:</TextBlock>
										<TextBlock DockPanel.Dock="Left" Name="PART_InstanceName" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}"></TextBlock>
									</DockPanel>

									<DockPanel DockPanel.Dock="Top" Margin="4 0 0 0">

										<ToggleButton ToolTip="Categorized" Width="24" Height="24" Padding="0" Margin="0" Background="LightGray" IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Categorized, UpdateSourceTrigger=PropertyChanged}">
											<Image Width="20" Height="20" Source="/WPG;component/Themes/Icons/grouped.png" />
										</ToggleButton>
										<ToggleButton ToolTip="Alphabetical" Width="24" Height="24" Padding="0" Margin="0">
											<Image Width="20" Height="20" Source="/WPG;component/Themes/Icons/abc.png" />
											<ToggleButton.IsChecked>
												<Binding Path="Categorized" RelativeSource="{RelativeSource TemplatedParent}" UpdateSourceTrigger="PropertyChanged">
													<Binding.Converter>
														<converters:BoolToOppositeConverter />
													</Binding.Converter>
												</Binding>
											</ToggleButton.IsChecked>
										</ToggleButton>

										<TextBox DockPanel.Dock="Left" Margin="8 0 8 0" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=SearchTextBoxStyle}}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Filter, UpdateSourceTrigger=PropertyChanged}"></TextBox>
									</DockPanel>

								</DockPanel>

								<Border Background="White" DataContext="{TemplateBinding local:PropertyGrid.ShowPreview}" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Width="44" Height="44" HorizontalAlignment="Right" Margin="8 8 8 8" Padding="2">
									<Border.Visibility>
										<Binding>
											<Binding.Converter>
												<BooleanToVisibilityConverter />
											</Binding.Converter>
										</Binding>
									</Border.Visibility>
									<Rectangle>
										<Rectangle.Fill>
											<VisualBrush Stretch="Uniform" Visual="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Instance}"></VisualBrush>
										</Rectangle.Fill>
									</Rectangle>
								</Border>
							</Grid>

							<Grid>
								<ItemsControl ItemsSource="{TemplateBinding local:PropertyGrid.Properties}" Background="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=PropertiesBackgroundBrush}}">
									<ItemsControl.Template>
										<ControlTemplate>
											<ScrollViewer VerticalScrollBarVisibility="Auto" CanContentScroll="False">
												<!--<VirtualizingStackPanel IsItemsHost="True" />-->
												<StackPanel IsItemsHost="True" />
											</ScrollViewer>
										</ControlTemplate>
									</ItemsControl.Template>
								</ItemsControl>

								<Thumb x:Name="PART_Thumb" HorizontalAlignment="Left" Width="5" Margin="7 0 0 0" Cursor="SizeWE">
									<Thumb.RenderTransform>
										<TranslateTransform X="{Binding NameWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PropertyGrid}}}" />
									</Thumb.RenderTransform>
									<Thumb.Template>
										<ControlTemplate>
											<Border Background="Transparent" />
										</ControlTemplate>
									</Thumb.Template>
								</Thumb>
							</Grid>


						</DockPanel>
						<GridSplitter DataContext="{TemplateBinding local:PropertyGrid.ShowDescription}" Height="3" Grid.ColumnSpan="3" ResizeDirection="Rows" HorizontalAlignment="Stretch" VerticalAlignment="Bottom">
							<GridSplitter.Visibility>
								<Binding>
									<Binding.Converter>
										<BooleanToVisibilityConverter />
									</Binding.Converter>
								</Binding>
							</GridSplitter.Visibility>
						</GridSplitter>
						<StackPanel Background="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ExpanderBackgroundBrush}}" Grid.Row="1" DataContext="{TemplateBinding local:PropertyGrid.ShowDescription}">
							<StackPanel.Visibility>
								<Binding>
									<Binding.Converter>
										<BooleanToVisibilityConverter />
									</Binding.Converter>
								</Binding>
							</StackPanel.Visibility>
                            <TextBlock Padding="2 2 2 0" FontWeight="Bold" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}" Text="{Binding Name}" DataContext="{TemplateBinding local:PropertyGrid.SelectedProperty}" ></TextBlock>
                            <TextBlock Padding="5 2 2 0" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}" TextWrapping="WrapWithOverflow" Text="{Binding Description}" DataContext="{TemplateBinding local:PropertyGrid.SelectedProperty}"></TextBlock>
						</StackPanel>
					</Grid>
                    </Border>
                </ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>